package photo.navi;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GpsManager {
	 public static GpsManager getInstance() {
	     return INSTANCE;
	 }
	 
	 public String getPosition(){
		 if(location == null){
			 location= locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
		 }
		 String position = location.getLatitude() + "," + location.getLongitude();
		 return position;
	 }

	 public void setLocationManager(LocationManager new_location_manager){
		 if(locationManager == null){
			 locationManager = new_location_manager;
			 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
			 locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
		 }
	 }
	 
	  // PRIVATE //
	  private static final GpsManager INSTANCE = new GpsManager();
	  private LocationManager locationManager;
	  private Location location;
	  
	  public LocationListener locationListener;
		  
	  private GpsManager() {
		 locationListener = new LocationListener() {
			    public void onLocationChanged(Location new_location) {
			      // Called when a new location is found by the network location provider.
			      location.set(new_location);
			    }

			    public void onStatusChanged(String provider, int status, Bundle extras) {}

			    public void onProviderEnabled(String provider) {}

			    public void onProviderDisabled(String provider) {}
			  };
	  }
}
